﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace QaaSimulation.QSim.Ships
{
    class QTurretBox : QShipBox
    {
        public QTurretBox()
            : base()
        {
            m_Crew = -5;
            m_Energy = -15;
        }

        public override void Paint(System.Drawing.Graphics g)
        {
            if (GetNeighbor(QBoxSide.Top) == null)
            {
                RectangleF rec = new RectangleF(0.3f * QModelBox.BOX_RELATION, -0.2f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION);
                g.FillEllipse(Brushes.DarkGray, rec);
                g.DrawEllipse(Pens.Black, rec);
            }

            if (GetNeighbor(QBoxSide.Bottom) == null)
            {
                RectangleF rec = new RectangleF(0.3f * QModelBox.BOX_RELATION, 0.8f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION);
                g.FillEllipse(Brushes.DarkGray, rec);
                g.DrawEllipse(Pens.Black, rec);
            }

            if (GetNeighbor(QBoxSide.Left) == null)
            {
                RectangleF rec = new RectangleF(-0.2f * QModelBox.BOX_RELATION, 0.3f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION);
                g.FillEllipse(Brushes.DarkGray, rec);
                g.DrawEllipse(Pens.Black, rec);
            }

            if (GetNeighbor(QBoxSide.Right) == null)
            {
                RectangleF rec = new RectangleF(0.8f * QModelBox.BOX_RELATION, 0.3f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION, 0.4f * QModelBox.BOX_RELATION);
                g.FillEllipse(Brushes.DarkGray, rec);
                g.DrawEllipse(Pens.Black, rec);
            }


            g.FillRectangle(new HatchBrush(HatchStyle.DarkUpwardDiagonal,Color.DarkRed), new Rectangle(0, 0, QModelBox.BOX_RELATION, QModelBox.BOX_RELATION));

            this.PaintWalls(g);
        }

        public override bool CanBePlaced(QShipBox[] neighborhood)
        {
            int neighborCount = 0;
            for (int i = 0; i < 4; i++)
                if (neighborhood[i] != null)
                    neighborCount++;

            return neighborCount < 4;
        }
    }
}
